<template>
  <transition name="MyDialog">
    <div class="dialog-overlay" ref="dialogDom" v-show="visible"
    :style="{ transition: `all ${transitionTime}` }">
      <div
      :style="{ width: widthPX || width + '%', height: heightPX || height + '%'}"
      class="dialog-modal">
        <div class="dialog-close" @click="close"></div>
        <slot></slot>
      </div>
    </div>
  </transition>
</template>

<script setup>

const props = defineProps({
  visible: {
    type:Boolean,
    default: false
  },
  width: {
    type: Number,
    default: 50
  },
  widthPX: {
    type: String,
    default: ''
  },
  height: {
    type: Number,
    default: 50
  },
  heightPX: {
    type: String,
    default: ''
  },
  transitionTime: {
    type: String,
    default: '0.3s'
  }
})

const emit = defineEmits(['update:visible'])

const close = () => {
  emit('update:visible', false)
}
</script>

<style scoped>
.dialog-overlay {
  opacity: 1;
  display: block;
  /* 默认不显示 */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  /* 半透明背景 */
  z-index: 999;
}

.dialog-modal {
  /* 默认不显示 */
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: url(../assets/img/login-resetpwd-bg.png) 0% 0% / 100% no-repeat rgb(255, 255, 255);
  border-radius: 16px;
  padding: 24px 38px;
  box-shadow: 0 0 24px rgba(0, 0, 0, .1);
  border: 1px solid #ddd;
  background-color: rgb(255, 255, 255);
  z-index: 1000;
}
.MyDialog-enter,
.MyDialog-leave-to {
  opacity: 0;
}

.dialog-close {
  width: 36px;
  height: 36px;
  cursor: pointer;
  background: url(../assets/icon/close.png) 50% / contain no-repeat;
  position: absolute;
  top: 10px;
  right: 10px;
}
</style>